'use strict';

import { EggAppConfig, PowerPartial } from 'egg';
import {join} from "path";
import {newEnforcer} from 'casbin';
export default function(appInfo: EggAppConfig) { 
  const config = {} as PowerPartial<EggAppConfig>;
  config.keys = appInfo.name + 'gdhome';
  config.cluster = {
      listen: {
        port: 8088,
      }
  };
  config.cors = {
    origin:'*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
  };
  config.sequelize = {
      dialect: 'mysql',
      host: '127.0.0.1',
      port: 3306,
      pool:{
        max:10,
        min:5,
        acquire: 30000,
        idle: 10000 // 如果一个线程 10 秒钟内没有被使用过的话，那么就释放线程
      },
      username:"root",
      password:"dkc230619",
      database:'gdhome',
      define:{
        'underscored':false,
        'charset': 'utf8',
        'collate': 'utf8_general_ci',
        'freezeTableName': true,
        'timestamps': true, 
      },
      timezone:'+08:00'
  };
  config.multipart = {
    mode: 'file',
    tmpdir: join(__dirname,"../app/public/"),
    cleanSchedule: {
      cron: '0 30 4 * * *'
    },
    fileSize:102400000000,
    files:100,
    whitelist:[
      '.xlsx','.xls','.png','.jpg','.gif','.jpeg','.mp4','.vhdx','.txt','.mp4','.exe'
    ]
  };
  config.bodyParser = {
    jsonLimit: '100mb',
    formLimit: '500mb',
  };
  config.jwt = {
    secret: "gaodehome"
  };
  //config.middleware=['authz'];
  config.authz={
    enable: true,
    newEnforcer: async function() {
      const enforcer = await newEnforcer()
      return enforcer
    }
  }
  config.redis = {
    client: {
      port: 6379,        
      host: '127.0.0.1', 
      password: '',
      db: 10,
    }
  }
  
  //自定义配置
  const bizConfig = {
    db_name:'gdhome',
    accessPath:'/download/',
    HOME_NEWS_LEN:6,
    HOME_RESOURCE_LEN:8,
    HOME_CATE_LEN:8,
    HOME_PRODUCT_LEN:8,
    HOME_SOLUTION_LEN:8,
    SOLUTION_CATE_ARR:["教学平台"],
    SYNC_SORT_TABLES:["banner","news","job","product","resource","sub","solution","product","category","product"]
  };
  
  return {
    ...config as {},
    ...bizConfig,
  };
}
